package com.ktjiaoyu.crm.mapper;

import com.ktjiaoyu.crm.entity.User;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    @Insert("INSERT INTO sys_user(usrname,usr_password,usr_role_id,usr_flag)"+"values (#{usrname},#{usr_password},#{usr_role_id},#{usr_flag})")
    public void insert(User user);
    @Delete("  DELETE FROM" +
            "                sys_user" +
            "            WHERE" +
            "                usrid=#{usrid}")
    public void delete(Long id);

    @Update({"<script>",
            "UPDATE sys_user",
            "<set>",
            "<if test='usrname!= null'>usrname = #{usrname},</if>",
            "<if test='usr_password!= null'>usr_password = #{usr_password},</if>",
            "<if test='usr_role_id!= null'>usr_role_id =  #{usr_role_id},</if>",
            "<if test='usr_flag!= null'>usr_flag = #{usr_flag},</if>",
            "</set>",
            "WHERE usrid = #{usrid}",
            "</script>"})
    public void update(User user);

    @Select("SELECT usrid,usrname,usr_password,usr_role_id,usr_flag from sys_user  WHERE usrid=#{usrid}")
    @Results({@Result(column = "usrid" ,property ="usrid" ),
            @Result(column = "usrname" ,property ="usrname" ),
            @Result(column = "usr_password" ,property ="usr_password" ),
            @Result(column = "usr_role_id" ,property ="usr_role_id" ),
            @Result(column = "usr_flag" ,property ="usr_flag" ),

    })
    public User get(Long id);

    @Select("SELECT usrid,usrname,usr_password,usr_role_id,usr_flag from sys_user ")
    @Results({@Result(column = "usrid" ,property ="usrid" ),
            @Result(column = "usrname" ,property ="usrname" ),
            @Result(column = "usr_password" ,property ="usr_password" ),
            @Result(column = "usr_role_id" ,property ="usr_role_id " ),
            @Result(column = "usr_flag" ,property ="usr_flag" ),
    })
    public List<User> findAll();
}
